package cn.com.backstage.controller.base;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ArrayList;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.ibm.icu.util.Calendar;

import cn.com.api.entity.ApiU_discover;
import cn.com.api.entity.ApiU_discover_cate;
import cn.com.api.entity.ApiU_discover_spec;
import cn.com.api.service.ApiU_discoverService;
import cn.com.api.service.ApiU_discover_cateService;
import cn.com.api.service.ApiU_discover_specService;
import cn.com.util.*;

public class U_discoverBaseController {

	private static Logger logger = Logger.getLogger(U_discoverBaseController.class);

	@Autowired
	private ApiU_discoverService apiU_discoverService;

	@Autowired
	private ApiU_discover_cateService apiU_discover_cateService;

	@Autowired
	private ApiU_discover_specService apiU_discover_specService;

	/**
	 * 列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_activity_discover-list")
	public ModelAndView u_activity_discover_list(HttpServletRequest request, HttpServletResponse response,
			PageInfo pageInfo) throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_list.jsp");

		List<ApiU_discover_cate> cates = this.apiU_discover_cateService.findU_discover_byType(0);
		Map conditions = new HashMap();

		String title = request.getParameter("activity_name");
		String cateId = request.getParameter("cateId");
		String status = request.getParameter("status");

		if (cateId != null && !cateId.equalsIgnoreCase("-1")) {
			conditions.put("cate_id", cateId);
		}
		if (title != null && !title.equalsIgnoreCase("")) {
			conditions.put("title", title);
		}
		if (status != null && !status.equalsIgnoreCase("-1")) {
			conditions.put("status", status);
		}
		conditions.put("type", "0");

		List<Map<String, Object>> u_discovers = apiU_discoverService.searchDiscover(conditions, pageInfo);
		mv.addObject("cates", cates);
		mv.addObject("u_discovers", u_discovers);
		mv.addObject("conditions", conditions);
		mv.addObject("pageInfo", pageInfo);

		return mv;
	}

	/**
	 * 进入新增或者编辑页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_activity_discover-add-pre")
	public ModelAndView u_activity_discover_add_pre(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_add.jsp");
		//
		if (request.getParameter("id") != null) {
			Integer id = Integer.valueOf(request.getParameter("id"));
			ApiU_discover u_discover = apiU_discoverService.findU_discoverById(id);
			mv.addObject("u_discover", u_discover);

			List<ApiU_discover_spec> specs = this.apiU_discover_specService
					.getApiU_discover_specsBydiscover_Id(request.getParameter("id"));
			mv.addObject("specs", specs);
		}

		List<ApiU_discover_cate> cates = this.apiU_discover_cateService.findU_discover_byType(0);

		mv.addObject("cates", cates);

		return mv;
	}

	/**
	 * 保存新发现活动
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "u_activity_discover-add")
	public void u_activity_discover_add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String cateId = request.getParameter("cateId");
		String headImg = request.getParameter("head_img");
		String vedio = request.getParameter("vedio");
		String title = request.getParameter("title");
		String address = request.getParameter("address");
		String beginTime = request.getParameter("begin_time");
		String endTime = request.getParameter("end_time");
		String description = request.getParameter("description");
		String[] chargenames = request.getParameterValues("chargenames");
		String[] chargefees = request.getParameterValues("chargefees");
		String[] chargelimits = request.getParameterValues("chargelimits");

		String discoverId = request.getParameter("id");

		Map<String, Object> map = new HashMap<String, Object>();

		if (discoverId.equalsIgnoreCase("")) {
			if (this.validateAddActivityDiscover(request)) {
				ApiU_discover apiU_discover = new ApiU_discover();

				apiU_discover.setActivity_type(cateId);
				apiU_discover.setAddress(address);
				apiU_discover.setVedio(vedio);
				apiU_discover.setTitle(title);
				apiU_discover.setHead_img(headImg);
				apiU_discover.setBegin_time(beginTime);
				apiU_discover.setEnd_time(endTime);
				apiU_discover.setDescription(description);
				apiU_discover.setIs_verify(0);
				apiU_discover.setIs_delete(0);
				apiU_discover.setIs_cancel(0);
				apiU_discover.setAdd_time(
						new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
				apiU_discover.setUser_id("1");// 暂时设置
				apiU_discover.setType(0);

				List<ApiU_discover_spec> specs = new ArrayList<ApiU_discover_spec>();
				for (int i = 0; i < chargenames.length; i++) {
					ApiU_discover_spec apiU_discover_spec = new ApiU_discover_spec();

					apiU_discover_spec.setPrice_name(chargenames[i]);
					apiU_discover_spec.setPrice(new BigDecimal(chargefees[i]));

					apiU_discover_spec.setLimit(Integer.valueOf(chargelimits[i]));
					apiU_discover.setPeople_limit(chargelimits[i]);

					apiU_discover_spec.setSort(i + 1);
					apiU_discover_spec.setType(0);

					specs.add(apiU_discover_spec);
				}

				this.apiU_discoverService.U_discoverInsertionWithSpec(apiU_discover, specs);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加成功！");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "传入数据不正确！");
			}
		} else {
			if (this.validateAddActivityDiscover(request)) {
				ApiU_discover apiU_discover = new ApiU_discover();

				apiU_discover.setId(Integer.valueOf(discoverId));
				apiU_discover.setActivity_type(cateId);
				apiU_discover.setAddress(address);
				apiU_discover.setVedio(vedio);
				apiU_discover.setTitle(title);
				apiU_discover.setHead_img(headImg);
				apiU_discover.setBegin_time(beginTime);
				apiU_discover.setEnd_time(endTime);
				apiU_discover.setDescription(description);
				apiU_discover.setIs_verify(0);
				apiU_discover.setIs_delete(0);
				apiU_discover.setIs_cancel(0);
				apiU_discover.setAdd_time(
						new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
				apiU_discover.setUser_id("1");// 暂时设置
				apiU_discover.setType(0);

				List<ApiU_discover_spec> specs = new ArrayList<ApiU_discover_spec>();
				for (int i = 0; i < chargenames.length; i++) {
					ApiU_discover_spec apiU_discover_spec = new ApiU_discover_spec();

					apiU_discover_spec.setPrice_name(chargenames[i]);
					apiU_discover_spec.setPrice(new BigDecimal(chargefees[i]));

					apiU_discover_spec.setLimit(Integer.valueOf(chargelimits[i]));
					apiU_discover.setPeople_limit(chargelimits[i]);

					apiU_discover_spec.setSort(i + 1);
					apiU_discover_spec.setType(0);

					specs.add(apiU_discover_spec);
				}

				this.apiU_discoverService.U_discoverUpdateWithSpec(apiU_discover, specs);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "修改成功！");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "传入数据不正确！");
			}
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 验证新增或修改新发现活动
	 * @param request
	 * @return
	 */
	private boolean validateAddActivityDiscover(HttpServletRequest request) {
		String cateId = request.getParameter("cateId");
		String vedio = request.getParameter("vedio");
		String title = request.getParameter("title");
		String address = request.getParameter("address");
		String beginTime = request.getParameter("begin_time");
		String endTime = request.getParameter("end_time");
		String[] chargenames = request.getParameterValues("chargenames");
		String[] chargefees = request.getParameterValues("chargefees");
		String[] chargelimits = request.getParameterValues("chargelimits");

		if (cateId.equalsIgnoreCase("")) {
			return false;
		}

		if (vedio.equalsIgnoreCase("")) {
			return false;
		}

		if (title.equalsIgnoreCase("")) {
			return false;
		}

		if (address.equalsIgnoreCase("")) {
			return false;
		}

		if (beginTime.equalsIgnoreCase("")) {
			return false;
		}

		if (endTime.equalsIgnoreCase("")) {
			return false;
		}

		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			if (sdf.parse(beginTime).after(sdf.parse(endTime))) {
				return false;
			}

			if (chargenames == null) {
				return false;
			} else {
				for (int i = 0; i < chargenames.length; i++) {
					if (chargenames[i].length() == 0) {
						return false;
					}

					if (Float.valueOf(chargefees[i]) < 0) {
						return false;
					}

					if (Integer.valueOf(chargelimits[i]) < 0) {
						return false;
					}
				}
			}
		} catch (Exception e) {
			return false;
		}

		return true;
	}

	

	/**
	 * 删除
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_discover-delete")
	public void u_discover_delete(HttpServletRequest request, HttpServletResponse response) throws Exception {

		Map<String, Object> map = new HashMap<String, Object>();
		String id = request.getParameter("id");

		// delete
		int ret_i = apiU_discoverService.deleteU_discover(Integer.valueOf(id));

		//
		if (ret_i > 0) {
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "删除成功！");
		}
		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_service_discover-list")
	public ModelAndView u_service_discover_list(HttpServletRequest request, HttpServletResponse response,
			PageInfo pageInfo) throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_service_list.jsp");

		List<ApiU_discover_cate> cates = this.apiU_discover_cateService.findU_discover_byType(1);
		Map conditions = new HashMap();

		String title = request.getParameter("activity_name");
		String cateId = request.getParameter("cateId");
		String status = request.getParameter("status");

		if (cateId != null && !cateId.equalsIgnoreCase("-1")) {
			conditions.put("cate_id", cateId);
		}
		if (title != null && !title.equalsIgnoreCase("")) {
			conditions.put("title", title);
		}
		if (status != null && !status.equalsIgnoreCase("-1")) {
			conditions.put("status", status);
		}
		conditions.put("type", "1");

		List<Map<String, Object>> u_discovers = apiU_discoverService.searchDiscover(conditions, pageInfo);
		mv.addObject("cates", cates);
		mv.addObject("u_discovers", u_discovers);
		mv.addObject("conditions", conditions);
		mv.addObject("pageInfo", pageInfo);

		return mv;
	}

	/**
	 * 进入新增或者编辑页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_service_discover-add-pre")
	public ModelAndView u_service_discover_add_pre(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_service_add.jsp");
		//
		if (request.getParameter("id") != null) {
			Integer id = Integer.valueOf(request.getParameter("id"));
			ApiU_discover u_discover = apiU_discoverService.findU_discoverById(id);
			mv.addObject("u_discover", u_discover);

			List<ApiU_discover_spec> specs = this.apiU_discover_specService
					.getApiU_discover_specsBydiscover_Id(request.getParameter("id"));
			mv.addObject("specs", specs);
		}

		List<ApiU_discover_cate> cates = this.apiU_discover_cateService.findU_discover_byType(1);

		mv.addObject("cates", cates);

		return mv;
	}

	@RequestMapping(value = "u_service_discover-verify")
	public ModelAndView u_service_discover_verify(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_service_verify.jsp");
		//
		if (request.getParameter("id") != null) {
			Integer id = Integer.valueOf(request.getParameter("id"));
			ApiU_discover u_discover = apiU_discoverService.findU_discoverById(id);
			mv.addObject("u_discover", u_discover);

			List<ApiU_discover_spec> specs = this.apiU_discover_specService
					.getApiU_discover_specsBydiscover_Id(request.getParameter("id"));
			mv.addObject("specs", specs);
		}

		List<ApiU_discover_cate> cates = this.apiU_discover_cateService.findU_discover_byType(1);

		mv.addObject("cates", cates);

		return mv;
	}

	/**
	 * 保存新发现活动
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "u_service_discover-add")
	public void u_service_discover_add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String cateId = request.getParameter("cateId");
		String headImg = request.getParameter("head_img");
		String image_list = request.getParameter("image_list");
		String vedio = request.getParameter("vedio");
		String title = request.getParameter("title");
		String address = request.getParameter("address");
		String beginTime = request.getParameter("begin_time");
		String endTime = request.getParameter("end_time");
		String description = request.getParameter("description");
		String[] chargenames = request.getParameterValues("chargenames");
		String[] chargefees = request.getParameterValues("chargefees");
		String[] chargelimits = request.getParameterValues("chargelimits");
		String isAdd = request.getParameter("is_add");

		String discoverId = request.getParameter("id");

		Map<String, Object> map = new HashMap<String, Object>();

		if (discoverId.equalsIgnoreCase("")) {
			if (this.validateAddActivityDiscover(request)) {
				ApiU_discover apiU_discover = new ApiU_discover();

				apiU_discover.setActivity_type(cateId);
				apiU_discover.setAddress(address);
				apiU_discover.setVedio(vedio);
				apiU_discover.setTitle(title);
				/**add start*/
				//apiU_discover.setHead_img(headImg);				
				apiU_discover.setHead_img(image_list);
				/**add end*/
				apiU_discover.setBegin_time(beginTime);
				apiU_discover.setEnd_time(endTime);
				apiU_discover.setDescription(description);
				apiU_discover.setIs_verify(0);
				apiU_discover.setIs_delete(0);
				apiU_discover.setIs_cancel(0);
				apiU_discover.setAdd_time(
						new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
				apiU_discover.setUser_id("1");// 暂时设置
				apiU_discover.setType(1);
				if (isAdd == null) {
					apiU_discover.setIs_add(0);
				} else {
					apiU_discover.setIs_add(1);
				}

				List<ApiU_discover_spec> specs = new ArrayList<ApiU_discover_spec>();
				for (int i = 0; i < chargenames.length; i++) {
					ApiU_discover_spec apiU_discover_spec = new ApiU_discover_spec();

					apiU_discover_spec.setPrice_name(chargenames[i]);
					apiU_discover_spec.setPrice(new BigDecimal(chargefees[i]));

					apiU_discover_spec.setLimit(Integer.valueOf(chargelimits[i]));
					apiU_discover.setPeople_limit(chargelimits[i]);

					apiU_discover_spec.setSort(i + 1);
					apiU_discover_spec.setType(1);

					specs.add(apiU_discover_spec);
				}

				this.apiU_discoverService.U_discoverInsertionWithSpec(apiU_discover, specs);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加成功！");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "传入数据不正确！");
			}
		} else {
			if (this.validateAddActivityDiscover(request)) {
				ApiU_discover apiU_discover = new ApiU_discover();

				apiU_discover.setId(Integer.valueOf(discoverId));
				apiU_discover.setActivity_type(cateId);
				apiU_discover.setAddress(address);
				apiU_discover.setVedio(vedio);
				apiU_discover.setTitle(title);
				apiU_discover.setHead_img(headImg);
				apiU_discover.setBegin_time(beginTime);
				apiU_discover.setEnd_time(endTime);
				apiU_discover.setDescription(description);
				apiU_discover.setIs_verify(0);
				apiU_discover.setIs_delete(0);
				apiU_discover.setIs_cancel(0);
				apiU_discover.setAdd_time(
						new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
				apiU_discover.setUser_id("1");// 暂时设置
				apiU_discover.setType(1);
				if (isAdd == null) {
					apiU_discover.setIs_add(0);
				} else {
					apiU_discover.setIs_add(1);
				}

				List<ApiU_discover_spec> specs = new ArrayList<ApiU_discover_spec>();
				for (int i = 0; i < chargenames.length; i++) {
					ApiU_discover_spec apiU_discover_spec = new ApiU_discover_spec();

					apiU_discover_spec.setPrice_name(chargenames[i]);
					apiU_discover_spec.setPrice(new BigDecimal(chargefees[i]));

					apiU_discover_spec.setLimit(Integer.valueOf(chargelimits[i]));
					apiU_discover.setPeople_limit(chargelimits[i]);

					apiU_discover_spec.setSort(i + 1);
					apiU_discover_spec.setType(1);

					specs.add(apiU_discover_spec);
				}

				this.apiU_discoverService.U_discoverUpdateWithSpec(apiU_discover, specs);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "修改成功！");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "传入数据不正确！");
			}
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	/**
	 * 列表
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_requirement_discover-list")
	public ModelAndView u_requirement_discover_list(HttpServletRequest request, HttpServletResponse response,
			PageInfo pageInfo) throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_requirement_list.jsp");

		Map conditions = new HashMap();

		String title = request.getParameter("activity_name");
		String status = request.getParameter("status");

		if (title != null && !title.equalsIgnoreCase("")) {
			conditions.put("title", title);
		}
		if (status != null && !status.equalsIgnoreCase("-1")) {
			conditions.put("status", status);
		}
		conditions.put("type", "2");

		List<Map<String, Object>> u_discovers = apiU_discoverService.searchDiscover(conditions, pageInfo);
		mv.addObject("u_discovers", u_discovers);
		mv.addObject("conditions", conditions);
		mv.addObject("pageInfo", pageInfo);

		return mv;
	}

	/**
	 * 进入新增或者编辑页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "u_requirement_discover-add-pre")
	public ModelAndView u_requirement_discover_add_pre(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_requirement_add.jsp");
		//
		if (request.getParameter("id") != null) {
			Integer id = Integer.valueOf(request.getParameter("id"));
			ApiU_discover u_discover = apiU_discoverService.findU_discoverById(id);
			mv.addObject("u_discover", u_discover);
		}

		return mv;
	}

	/**
	 * 保存新发现需求
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "u_requirement_discover-add")
	public void u_requirement_discover_add(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String headImg = request.getParameter("head_img");
		String title = request.getParameter("title");
		String address = request.getParameter("address");
		String beginTime = request.getParameter("begin_time");
		String endTime = request.getParameter("end_time");
		String description = request.getParameter("description");
		String isAdd = request.getParameter("is_add");

		String discoverId = request.getParameter("id");

		Map<String, Object> map = new HashMap<String, Object>();

		if (discoverId.equalsIgnoreCase("")) {
			if (this.validateAddRequirementDiscover(request)) {
				ApiU_discover apiU_discover = new ApiU_discover();

				apiU_discover.setAddress(address);
				apiU_discover.setTitle(title);
				apiU_discover.setHead_img(headImg);
				apiU_discover.setBegin_time(beginTime);
				apiU_discover.setEnd_time(endTime);
				apiU_discover.setDescription(description);
				apiU_discover.setIs_verify(0);
				apiU_discover.setIs_delete(0);
				apiU_discover.setIs_cancel(0);
				apiU_discover.setAdd_time(
						new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
				apiU_discover.setUser_id("1");// 暂时设置
				apiU_discover.setType(2);
				if (isAdd == null) {
					apiU_discover.setIs_add(0);
				} else {
					apiU_discover.setIs_add(1);
				}
				System.out.println("yesyesye");
				List<ApiU_discover_spec> specs = new ArrayList<ApiU_discover_spec>();

				this.apiU_discoverService.U_discoverInsertionWithSpec(apiU_discover, specs);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "添加成功！");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "传入数据不正确！");
			}
		} else {
			if (this.validateAddRequirementDiscover(request)) {
				ApiU_discover apiU_discover = new ApiU_discover();

				apiU_discover.setId(Integer.valueOf(discoverId));
				apiU_discover.setAddress(address);
				apiU_discover.setTitle(title);
				apiU_discover.setHead_img(headImg);
				apiU_discover.setBegin_time(beginTime);
				apiU_discover.setEnd_time(endTime);
				apiU_discover.setDescription(description);
				apiU_discover.setIs_verify(0);
				apiU_discover.setIs_delete(0);
				apiU_discover.setIs_cancel(0);
				apiU_discover.setAdd_time(
						new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
				apiU_discover.setUser_id("1");// 暂时设置
				apiU_discover.setType(2);
				if (isAdd == null) {
					apiU_discover.setIs_add(0);
				} else {
					apiU_discover.setIs_add(1);
				}

				List<ApiU_discover_spec> specs = new ArrayList<ApiU_discover_spec>();

				this.apiU_discoverService.U_discoverUpdateWithSpec(apiU_discover, specs);

				map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
				map.put(Utils.MESSAGE, "修改成功！");
			} else {
				map.put(Utils.RESULT, Utils.RESULT_RC_CHECK_FAIL);
				map.put(Utils.MESSAGE, "传入数据不正确！");
			}
		}

		JsonUtil.printJson(response, JsonUtil.object2json(map));
	}

	@RequestMapping(value = "u_requirement_discover-verify")
	public ModelAndView u_requirement_discover_verify(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_discover_requirement_verify.jsp");
		//
		if (request.getParameter("id") != null) {
			Integer id = Integer.valueOf(request.getParameter("id"));
			ApiU_discover u_discover = apiU_discoverService.findU_discoverById(id);
			mv.addObject("u_discover", u_discover);
		}

		return mv;
	}

	private boolean validateAddRequirementDiscover(HttpServletRequest request) {
		String title = request.getParameter("title");
		String address = request.getParameter("address");
		String beginTime = request.getParameter("begin_time");
		String endTime = request.getParameter("end_time");

		if (title.equalsIgnoreCase("")) {
			return false;
		}

		if (address.equalsIgnoreCase("")) {
			return false;
		}

		if (beginTime.equalsIgnoreCase("")) {
			return false;
		}

		if (endTime.equalsIgnoreCase("")) {
			return false;
		}

		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

			if (sdf.parse(beginTime).after(sdf.parse(endTime))) {
				return false;
			}

		} catch (Exception e) {
			return false;
		}

		return true;
	}
}
